package Controller;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import Model.Bankkonto;
import Model.Payload;
import Model.Queue;
import View.ViewEingabe;


public class ControllerEingabe {
	private ViewEingabe view;
	private Queue queue = Queue.getInstance();
	
	public ControllerEingabe(ViewEingabe view) {
		setView(view);
		
		init();
		registerEvents();
	}

	public void init() {
		
	}
	
	public void registerEvents() {
		MyMouseAdapter mouse = new MyMouseAdapter();

		view.getBtnSend().addMouseListener(mouse);
	}
	
	class MyMouseAdapter extends MouseAdapter {
		public void mouseClicked(MouseEvent e) {
			Object object = e.getSource();

			if (object == view.getBtnSend()) {
				sendMouseEvent();
			}
		}
	}
	
	public void sendMouseEvent() {
		String name = view.getTfMessage().getText();
		int kontoNr = Integer.parseInt(view.getTfKontoNr().getText());
		double kontostand = Double.parseDouble(view.getTfKontostand().getText());
		String task = (String) view.getCbTask().getSelectedItem();

		queue.add(new Payload(task, new Bankkonto(kontoNr, kontostand, name), "Bankkonto", "WAITING", "192.168.0.20", 1235, 6));		
		view.getTfMessage().setText("");
		view.getTfKontoNr().setText("");
		view.getTfKontostand().setText("");
	}
	
	public ViewEingabe getView() {
		return view;
	}

	public void setView(ViewEingabe view) {
		this.view = view;
	}
	
	
}
